package com.hs.wa.controller;

import com.hs.wa.entity.User;
import com.hs.wa.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@CrossOrigin
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/register")
    @ResponseBody  /* 解决 Unknown return value type: java.lang.Boolean*/
    public boolean registerUser(User user) {
        boolean flag = false;
        flag = userService.addUser(user);

        return flag;
    }

    @PostMapping("/login")
    @ResponseBody  /* 解决 Unknown return value type: java.lang.Boolean*/
    public ResponseEntity loginUser(User user) {
        boolean flag = false;
        flag = userService.selectUser(user);
        if (flag) {
            return ResponseEntity.ok().build();
        }

        return ResponseEntity.badRequest().build();
    }
}
